// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Axios from 'axios'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
import 'normalize.css'
import './assets/css/global.css'
import MyUl from '@/components/common/MyUl'
import MyLi from '@/components/common/MyLi'
import MySwipe from '@/components/common/MySwipe'
import Moment from 'moment'
import NavBar from '@/components/common/NavBar'
import BaseHeaderTitle from '@/components/common/BaseHeaderTitle'
import VuePreview from 'vue-preview'
import ContentBody from '@/components/common/ContentBody'

Vue.use(MintUI)
Vue.use(VuePreview)
Vue.component(MyUl.name, MyUl)
Vue.component(MyLi.name, MyLi)
Vue.component(MySwipe.name, MySwipe)
Vue.component(NavBar.name, NavBar)
Vue.component(BaseHeaderTitle.name, BaseHeaderTitle)
Vue.component(ContentBody.name, ContentBody)

Vue.config.productionTip = false
Axios.defaults.baseURL = 'https://www.sinya.online/api/'
Vue.prototype.$axios = Axios
Vue.prototype.$preview = VuePreview
// 配置请求拦截器，加载loading
Axios.interceptors.request.use(config => {
  MintUI.Indicator.open({
    text: '玩命加载中...'
  })
  return config
})
Axios.interceptors.response.use(response => {
  MintUI.Indicator.close()
  return response
})
// 时间插件全局过滤器
Vue.filter('convertTime', (time, formatStr) => {
  return Moment(time).format(formatStr)
})
// 时间过滤器，多久之前
Vue.filter('relativeTime', function (previousTime) {
  return Moment(previousTime).fromNow()
})
// 处理字符串过长过滤器
Vue.filter('convertStr', (str, count) => {
  return str.substring(0, count) + '...'
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {
    App
  },
  template: '<App/>'
})
